﻿using DataAccess.DAL;
using DataAccess.DTO;
using DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Web.Controllers
{
    public class TbkOrderController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public JsonResult GetTbkOrders()
        {

            string OrderID = System.Web.HttpContext.Current.Request.Form["OrderID"];
            int ProductID = XYD.Common.Request.GetFormInt("ProductID", 0);

            int limit = XYD.Common.Request.GetFormInt("limit", 10);
            int offset = XYD.Common.Request.GetFormInt("offset", 1);
            int category = XYD.Common.Request.GetFormInt("category", 0);
            string AdvName = System.Web.HttpContext.Current.Request.Form["AdvName"];

            if (limit > 100) { limit = 10; }



            string strWhere = " 1=1 ";
            string orderbys = "";

            if (!string.IsNullOrEmpty(OrderID))
            {
                strWhere += " and OrderID='"+ OrderID + "'";
            }
            if (ProductID != 0)
            {
                strWhere += "and ProductID=" + ProductID;
            }
            int count = 0;

            List<Orders> tbkItems = new DataAccess.DAL.OrdersDAL().ListPage(UserSession.user_id, strWhere, orderbys, limit, (offset / limit) + 1, out count);

            Result result = new Result();
            result.State = true;
            result.Message = "查询成功";
            result.Datas = new PageData<Orders> { Total = count, Rows = tbkItems, PageIndex = (offset / limit) + 1, PageSize = limit };
            return Json(result);
        } 
       
    }
}